﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Threading;

namespace KZ400B.Controls
{
    public class WpfEvent
    {
        //private static DispatcherOperationCallback exitFrameCallback = new DispatcherOperationCallback(ExitFrame);
        //public static void DoEvents()
        //{
        //    DispatcherFrame nestedFrame = new DispatcherFrame();
        //    DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke
        //        (DispatcherPriority.Background, exitFrameCallback, nestedFrame);
        //    Dispatcher.PushFrame(nestedFrame);
        //    if (exitOperation.Status != DispatcherOperationStatus.Completed)
        //    {
        //        exitOperation.Abort();
        //    }
        //}

        //private static Object ExitFrame(Object state)
        //{ DispatcherFrame frame = state as DispatcherFrame; frame.Continue = false; return null; }
        public static void DoEvents()
        {
            DispatcherFrame frame = new DispatcherFrame();
            Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
                new DispatcherOperationCallback(ExitFrame), frame);
            Dispatcher.PushFrame(frame);
        }

        private static object ExitFrame(object f)
        {
            ((DispatcherFrame)f).Continue = false;

            return null;
        }
    }
}
